package defaultproperty.classes;

import java.util.Hashtable;
import pool.bean.*;
import User.Uservalidation;
import dbmanager.DBManager;
import dbmanager.GetIdName;


public class Autoincrement implements Class
{
		DBManager database;
		Hashtable<Object ,Object> table = new Hashtable<Object, Object>();
		String LASTVALUE="lastvalue";
		String Object;
		String SYSTEMUSER="+911234567891";
		GetIdName gid;
		
		public String getResult() 
		{
			Uservalidation user =new  Uservalidation(database);
			String PASSWORD=user.getPasword(SYSTEMUSER);
			
			if(table.containsKey(LASTVALUE))
			{
				int lastvalue = Integer.parseInt(table.get(LASTVALUE).toString());
				control.RequestParameter req = new control.RequestParameter();
				req.setUsername(SYSTEMUSER);
				req.setMessage("System Message");
				req.setPassword(PASSWORD);
				req.setRequest("proerty_details");
				req.setProcess("mod");
				Property_details_Bean propertybean = new Property_details_Bean();
				propertybean.setReqParam(req);
				propertybean.setDBManager(database);
				Hashtable<Object, Object> oldmap = new Hashtable<Object, Object>();
				oldmap.put("mid", Object);
				oldmap.put("pid", LASTVALUE);
				oldmap.put("pv", lastvalue);
				
				Hashtable<Object, Object> newmap = new Hashtable<Object, Object>();
				newmap.put("mid", Object);
				newmap.put("pid", LASTVALUE);
				newmap.put("pv", lastvalue+1);
				propertybean.setOldPropertyHash(oldmap);
				propertybean.setNewPropertyHash(newmap);
				propertybean.update();
				return Integer.toString(lastvalue+1);
			}
			else
			{
				control.RequestParameter req = new control.RequestParameter();
				req.setUsername(SYSTEMUSER);
				req.setMessage("System Message");
				req.setPassword(PASSWORD);
				req.setRequest("proerty_details");
				req.setProcess("mod");
				Property_details_Bean propertybean = new Property_details_Bean();
				propertybean.setReqParam(req);
				Hashtable<Object, Object> oldmap = new Hashtable<Object, Object>();
				oldmap.put("mid", Object);
				oldmap.put("pid", LASTVALUE);
				oldmap.put("pv", "1");
				propertybean.setOldPropertyHash(oldmap);
				propertybean.insert();
				return Integer.toString(1);
			}	
			
		}
		
		
		public void setObject(DBManager database) 
		{	
			this.database = database;
			gid =new GetIdName(database);
		}

		public void setPropertymap(Hashtable<Object, Object> propetrymap,String Object) 
		{
			this.table.putAll(propetrymap);
			this.Object = gid.getItem(Object);
		}
}
